using UnityEngine;

public class Waypoint : MonoBehaviour
{
    [SerializeField] private Vector3[] points; // 存储路径点的数组
    private Vector3 _currentPosition; // 当前位置
    private bool _gameStarted; // 游戏是否已经开始

    public Vector3[] Points => points;
    public Vector3 CurrentPosition => _currentPosition;

    private void Start()
    {
        _gameStarted = true;
        _currentPosition = transform.position;
    }

    // 在Scene视图中绘制路径点和连线
    private void OnDrawGizmos()
    {
        if (!_gameStarted && transform.hasChanged)
        {
            _currentPosition = transform.position;
        }

        // 绘制路径点
        for (int i = 0; i < points.Length; i++)
        {
            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(center: points[i] + _currentPosition, radius: 0.5f);

            // 绘制路径线
            if (i < points.Length - 1)
            {
                Gizmos.color = Color.gray;
                Gizmos.DrawLine(points[i] + _currentPosition, points[i + 1] + _currentPosition);
            }
        }
    }

    //获取指定索引的路径点位置
    public Vector3 GetWaypointPosition(int index)
    {
        return CurrentPosition + Points[index];
    }
}